package com.zhou.learn.controller;

import com.zhou.entities.Provider;
import com.zhou.learn.dao.MybatisAnnotationMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 供应商的控制层
 */
@RestController
public class MybatisAnnotationController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    //这是采用jdbc的方式去操作数据库的，用了mybatis就不用这个了
    @Autowired
    private MybatisAnnotationMapper mybatisAnnotationMapper;

    @GetMapping("/mybatis/provider/{id}")
    public Provider mybatisQuery(@PathVariable("id") Integer id){
        Provider provider = mybatisAnnotationMapper.queryProviderByPid(id);
        return provider;
    }

    @GetMapping("/mybatis/provider")
    public Provider mybatisAdd(Provider provider){
        mybatisAnnotationMapper.insertProvider(provider);
        return provider;
    }

}
